package testy;

import java.util.ArrayList;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class Graph extends JFrame
{
    public Graph(final String title, ArrayList<Double> list, XYSeriesCollection dataset)
    { 
        JFreeChart chart = createChart(dataset, title);   
        ChartPanel chartPanel = new ChartPanel(chart);
        // default size
        chartPanel.setPreferredSize(new java.awt.Dimension(900, 450));
        // add it to our application
        setContentPane(chartPanel);
    }
    
    public XYSeries xySeries(ArrayList<Double> list, String title)
    {
    	XYSeries series = new XYSeries(title);
    	for (int i = 0; i <= 24; i++)
    	{
            series.add(i, list.get(i));
    	}
    	return series;
    }
    
    /**
     * @param args the command line arguments
     */
    public static JFreeChart createChart(XYDataset dataset, String title) 
    {
        JFreeChart chart = ChartFactory.createXYLineChart("Strøm", "tid", "W/h", dataset, PlotOrientation.VERTICAL, true, false, true);
        return chart;
    }    
}
